﻿using HrEFCore;
using HrIService;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HrService
{
	public class CMService : ICMService
	{
		private readonly MyDbContext myDbContext;

		public CMService(MyDbContext myDbContext)
        {
			this.myDbContext = myDbContext;
		}
        public CMService()
        {
            
        }
		public Task<List<CM>> CMSelectAsync()
		{
			return myDbContext.CM.ToListAsync();
		}

		public async Task<int> CMDeleteAsync(short MakId)
		{
			var zhi = await myDbContext.CM.FindAsync(MakId);
			if(zhi == null)
			{
				return 0;
			}
			myDbContext.CM.Remove(zhi);
			return await myDbContext.SaveChangesAsync();
		}

		public async Task<int> CMAddAsync(CM cm)
		{
			myDbContext.CM.AddAsync(cm);
			return await myDbContext.SaveChangesAsync();
		}
	}
}
